package cn.edu.hbpu.common;

import cn.edu.hbpu.handler.CustomException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author lcy
 * @date 2022/8/6 14:46
 * @description
 */
@RestController
public class FilterExceptionController {

    /**
     * 过滤器抛出的异常不能处理，所以提供一个过滤器用来将异常转发到该方法，从而在controller方法中抛出异常，从而被捕获
     * @param request
     */
    @RequestMapping("/handleFilterException")
    public void handleFilterException(HttpServletRequest request) throws CustomException {
        Exception exception = (Exception) request.getAttribute("filterException");
        throw new CustomException(exception.getMessage());
    }
}
